<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="input">
    <script>
        var input = document.getElementById("input");
        var searchs = [{
            spell: "A",
            citys: [{
                    name: "阿里",
                    id: 1001
                },
                {
                    name: "阿拉",
                    id: 1001
                },
                {
                    name: "阿克",
                    id: 1001
                }
            ]
        }, {
            spell: "T",
            citys: [{
                    name: "天下",
                    id: 2001
                },
                {
                    name: "天天",
                    id: 2002
                },
                {
                    name: "天里",
                    id: 2003
                }
            ]
        }]
        /*
        input输入 里 
         */
        //    var arr = [
        //        {    name:"天里",id:2003},{name:"阿里",id:1001}
        //    ]
        var input = document.getElementById("input");
        input.onkeydown  = function(e){
            if(e.keyCode==13&&this.value!=''){
                var keyword = this.value;
                var arr=[];
                searchs.forEach(item=>{
                    item.citys.forEach(k=>{
                        if(k.name.includes(keyword)){
                            arr.push(k)
                        }
                    })
                })
                console.log(arr)
            }
        }
        </script>
</body>
</html>